package com.mf.all.controller;


import com.mf.all.emuns.enumsPublic.EnumPublicEnableOrDisable;
import com.mf.all.entity.req.publicReq.updateStatus.ReqPublicIntIdUpdateStatus;
import com.mf.all.groups.GroupsAddInterface;
import com.mf.all.groups.GroupsUpdateInterface;
import com.mf.all.result.Result;
import com.mf.all.utils.UtilController;
import com.mf.all.utils.UtilsEnum;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import cn.dev33.satoken.annotation.SaCheckPermission;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;


import com.mf.all.entity.dto.DtoMaterial;
import com.mf.all.entity.req.basic.ReqMaterial;
import com.mf.all.service.ServiceMaterial;
import com.mf.all.entity.req.search.basic.SearchReqMaterial;

import java.util.Arrays;
import java.util.List;

/**
 * 物料表
 *
 * @date 2025-04-02 22:36:46
 */
@RestController
@RequestMapping("material")
@Tag(name = "物料表")
public class ControllerMaterial {
    @Resource
    private ServiceMaterial Servicematerial;

    @Operation(summary = "分页列表查询")
    @PostMapping("/page")
    @SaCheckPermission("material:search")
    public Result<Page<DtoMaterial>> findPage(@RequestBody SearchReqMaterial searchReqMaterial) {
        return Result.success(Servicematerial.findPageByParams(searchReqMaterial));
    }

    @Operation(summary = "列表查询")
    @PostMapping("/list")
    @SaCheckPermission("material:search")
    public Result<List<DtoMaterial>> list(@RequestBody SearchReqMaterial searchReqMaterial) {
        return Result.success(Servicematerial.findListByParams(searchReqMaterial));
    }

    @Operation(summary = "保存")
    @PostMapping("/save")
    @SaCheckPermission("material:save")
    public Result<Void> save(@Validated(GroupsAddInterface.class) @RequestBody ReqMaterial reqMaterial) {
        Servicematerial.saveMaterial(UtilController.setBo(reqMaterial, DtoMaterial.class));
        return Result.success();
    }

    @Operation(summary = "修改")
    @PostMapping("/update")
    @SaCheckPermission("material:update")
    public Result<Void> update(@Validated(GroupsUpdateInterface.class) @RequestBody ReqMaterial reqMaterial) {
        Servicematerial.updateMaterialById(UtilController.setBo(reqMaterial, DtoMaterial.class));
        return Result.success();
    }

    @Operation(summary = "修改状态")
    @PostMapping("/updateStatus")
    @SaCheckPermission("material:updateStatus")
    public Result<Void> delete(@Validated @RequestBody ReqPublicIntIdUpdateStatus updateStatus) {

        Servicematerial.updateStatusById(UtilController.setBo(updateStatus, DtoMaterial.class));
        return Result.success();
    }

}
